<?php
/**
 * Created by PhpStorm.
 * User: Talent
 * Date: 2018/5/16
 * Time: 17:50
 */
namespace app\admin\controller;
use think\Controller;
use veda\util\Tools;
use think\Session;
use app\admin\model\User;
class Login extends Controller{

    public function index(){
        $this->assign([
            'uuid'  => Tools::uuid(),
        ]);

        $user=Session::get("user");
//        $basic=Basic::get(["uuid"=>'80a57367-b79a-26e7-3eca-627f0d70beb7']);
//        $this->assign([
//            'system_name' => $basic->system_name,
//        ]);

        if($user==null){
            return $this->fetch('login');
        } else{
            $this->redirect('/admin/index/index');
        }
        return $this->fetch('index');
        return view("index");
    }
    public function login($name='',$password=''){
        if(''==$name || ''==$password){
            $this->error('用户名或密码不能为空！');
        }
        else{
            $user_data=User::all(['name'=>$name,'password'=>$password]);
            if(count( $user_data)==1) {
                $user= $user_data[0];

                if (! $user->name==$name && $user->password==$password) {
                    exit();
                }
//                $user->session=strtolower(Tools::uuid());
                $user->save();
                Session::set("user",$user);
                    $this->success('正在进入系统……','admin/index/index');
            }
            else{

                $this->error('用户名或密码错误！');
                //echo '登录失败！';
            }
        }
    }
}